require('./PageDbrwtxsh.styl');

const reactMixin = require('react-mixin');
const Actions = require('./../dbrwtxedit/actions');
const Store = require('./../dbrwtxedit/store');
import {Button, Group, TextareaField} from 'saltui';
import Reflux from 'reflux';

class Dbrwtxsh extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      yj: ''
    };
    this.onShyjChange = this.onShyjChange.bind(this);
    this.onSendClick = this.onSendClick.bind(this);
  }

  onShyjChange(obj) {
    this.setState({
      yj: obj,
    })
  }

  onSendClick() {
    let t = this;
    Actions.rwSend(
      {
        shyj: this.state.yj,
        shjl: this.props.params.operType == '0' ? '审核通过' : '审核退回',

      }, this.addCallBack, this
    )
  }

  addCallBack(t) {
    t.props.history.replaceState(null, '/dbrwtx');
  }


  render() {
    return (
      <div className="dbrwtxsh">
        <Group>
          <Group.List>
            <TextareaField label="" minRows={7} maxRows={15}
                           onChange={this.onShyjChange}
                           value={this.state.yj}
                           placeholder={'请输入'+ (this.props.params.operType=='0' ? '同意' : '拒绝') +'理由(非必填)'}
            />
          </Group.List>


          <Button style={{margin:'10px'}} type="primary"
                  onClick={this.onSendClick}>确定</Button>

        </Group>
      </div>
    );
  }

  componentWillMount() {
    let t = this;

    dd.biz.navigation.setTitle({
      title: '审批意见',//控制标题文本，空字符串表示显示默认文本
      onSuccess: function (result) {
      },
      onFail: function (err) {
        console.log(err);
        alert("调用钉钉设置导航接口错误:" + JSON.stringify(err));
      }
    });

    //dd.biz.navigation.setRight({
    //  show: true,//控制按钮显示， true 显示， false 隐藏， 默认true
    //  control: true,//是否控制点击事件，true 控制，false 不控制， 默认false
    //  text: '确定',//控制显示文本，空字符串表示显示默认文本
    //  onSuccess: function (result) {
    //    t.onSendClick();
    //
    //  }
    //});
  }
}

Dbrwtxsh.contextTypes = {
  router: React.PropTypes.object,
};

reactMixin.onClass(Dbrwtxsh, Reflux.connect(Store, ""));

module.exports = Dbrwtxsh;
